<?php
require_once FOREGROUND_COMMON_ACTION_SERVICE_DIR . '/default.php';

class foreground_good_info_action_service extends foreground_default_common_action_service
{
    protected static $_instance;

    public static function get_instance()
    {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }

        return self::$_instance;
    }


    protected function _current_page_process()
    {
        //var_dump(__METHOD__); exit();
        
        $result = array('status' => 0, 'message' => '', 'data' => array());
	    
	    self::add_view_data('page_title', '商品信息');
	    
	    $request_data = $_GET;
	    //var_dump($request_data); exit();
	    
	    $id = init_user_data_key($request_data, 'id', 'int');
	    //var_dump($id); exit();
	    
	    $cache_handler = wwy_resource_container::get_cache_handler();
	    $model_foreground_good = wwy_resource_container::get_model_foreground_good();
	    //var_dump($model_foreground_good); exit();    
	    
	    //$good_info = $model_foreground_good->find($id);
	    $good_info = $cache_handler->call(array($model_foreground_good, 'find'), array($id));

	    if(empty($good_info)){
	        $result['status']  = -3;
	        $result['message'] = '该商品不存在';
	    }else{	     
    	    //获取动态属性
    	    $where = array('good_id' => $id);
    	    $order = array('`order` asc');
    	    //$attr_list = $model_foreground_good->get_attr_list($where, $order);
    	    $attr_list = $cache_handler->call(array($model_foreground_good, 'get_attr_list'), array($where, $order));
    	    //var_dump($attr_list); exit();
    	    $good_info['attr_list'] = $attr_list;
    	    //var_dump($good_info); exit();
    	     
    	    //获取规格动态属性
    	    $where = array('good_id' => $id);
    	    $order = array('`order` asc');
    	    //$sattr_list = $model_foreground_good->get_sattr_list($where, $order);
    	    $sattr_list = $cache_handler->call(array($model_foreground_good, 'get_sattr_list'), array($where, $order));
    	    //var_dump($sattr_list); exit();
    	    $good_info['sattr_list'] = $sattr_list;
    	    $good_info['sattr_list_count'] = count($sattr_list);
    	    //var_dump($good_info); exit();
    	    
    	    //获取数量范围
    	    $where = array('good_id' => $id);
    	    $order = array('`order` asc');
    	    //$number_grade_list = $model_foreground_good->get_number_grade_list($where, $order);
    	    $number_grade_list = $cache_handler->call(array($model_foreground_good, 'get_number_grade_list'), array($where, $order));
    	    //var_dump($number_grade_list); exit();
    	    $good_info['number_grade_list'] = $number_grade_list;
    	    //var_dump($good_info); exit();
    	     
    	    //获取规格
    	    $where = array('good_id' => $id);
    	    $order = array('`order` asc');
    	    //$spec_list = $model_foreground_good->get_spec_list($where, $order);
    	    $spec_list = $cache_handler->call(array($model_foreground_good, 'get_spec_list'), array($where, $order));
    	    //var_dump($spec_list); exit();
    	    $good_info['spec_list'] = $spec_list;
    	    //var_dump($good_info); exit();
    	    
    	    //增加查看次数
    	    $good_info['click'] = $good_info['click'] + 1;
    	    $model_foreground_good->increase_click($id);
    	    
    	    self::add_view_data('good_info', $good_info);
    	    
    	    $model_foreground_good_category = wwy_resource_container::get_model_foreground_good_category();
    	    //var_dump($model_foreground_good_category); exit();
    	    $cat_id = $good_info['cat_id'];
    	    //$index_cats = $model_foreground_good_category->get_index_cats($cat_id);
    	    $index_cats = $cache_handler->call(array($model_foreground_good_category, 'get_index_cats'), array($cat_id));
    	    //var_dump($index_cats); exit();
    	    self::add_view_data('index_cats', $index_cats);
	    	    
    	    //SEO:title,keywords,description
    	    self::add_view_data('page_title', $good_info['name']); 	    
	    }
	    
	    self::set_view_status($result['status']);
	    self::set_view_message($result['message']);
    }
}